package com.suxin.websocket.handler;


import com.suxin.websocket.config.ThreadPoolBuilder;
import com.suxin.websocket.model.BaseModel;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author Tang
 * @classname AbstractHandler
 * @description [  ]
 * @date 2022/3/24 14:30
 */
public abstract class AbstractHandler<T extends BaseModel> implements Handler<T> {

    ThreadPoolExecutor threadPoolExecutor = ThreadPoolBuilder.defaultBuild();

    @Override
    public void handler(T data) {
        threadPoolExecutor.execute(new Task(data));
    }

    /**
     * handler0
     *
     * @param data
     */
    public abstract void handler0(T data);

    class Task implements Runnable {

        T data;

        public Task(T data) {
            this.data = data;
        }

        @Override
        public void run() {
            handler0(data);
        }
    }
}